package cn.edu.seu.cose.qol.ws.resource.questionnaire.strategy;

import java.util.HashMap;
import java.util.Map;

public class QuestionBaseStrategyFactory {
	
	public static final String TRUE_OR_FALSE = "true-or-false";
	
	public static final String CHOICE = "choice";
	
	public static final String SHORT_ANSWER = "short-answer";
	
	private static QuestionBaseStrategyFactory _instance;
	
	private Map<String, QuestionBaseStrategy> _strategies;
	
	public static QuestionBaseStrategyFactory genInstance() {
		if (_instance == null) {
			_instance = new QuestionBaseStrategyFactory();
		}
		return _instance;
	}
	
	protected QuestionBaseStrategyFactory() {
		_strategies = new HashMap<String, QuestionBaseStrategy>();
		register();
	}
	
	private void register() {
		_strategies.put(TRUE_OR_FALSE, new TrueOrFalseStrategy());
		_strategies.put(CHOICE, new ChoiceStrategy());
		_strategies.put(SHORT_ANSWER, new ShortAnswerStrategy());
	}
	
	public QuestionBaseStrategy getQuestionBaseStrategyByName(
			String name) throws NoSuchStrategy {
		if (!_strategies.containsKey(name)) {
			throw new NoSuchStrategy(name);
		}
		return _strategies.get(name);
	}

}
